{  Statement: http://acmp.ru/?main=task&id_task=99
   Verdict: Accepted
}
uses
  SysUtils, Math;

type
  point = record
    k,i,j:longint;
  end;

var
  i,j,kk,n,m,k,cur,h,t,x,y,z:longint;
  a,w:array[0..60,0..60,0..60] of boolean;
  b:array[0..60,0..60,0..60] of longint;
  q:array[0..2160010,1..3] of longint;
  p1,p2:point;
  ch:char;

function check():boolean;
begin
result := b[p2.k][p2.i][p2.j] = -1;
end;

procedure put(x,y,z:longint);
begin
if (not a[x][y][z]) or (b[x][y][z] <> -1) or (x > k) or (y < 1) or (y > n) or
  (z < 1) or (z > m) or w[x][y][z] then exit;
b[x][y][z] := cur;
inc(t);
q[t][1] := x;
q[t][2] := y;
q[t][3] := z;
w[x][y][z] := true; 
end;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
fillchar(a,sizeof(a),true);
fillchar(w,sizeof(w),0);
readln(k,n,m);
for kk := 1 to k do begin
  for i:=1 to n do begin
    for j:=1 to m do begin
      read(ch);
      if ch = '1' then begin
        p1.k := kk;
        p1.i := i;
        p1.j := j;
      end else
      if ch = '2' then begin
        p2.k := kk;
        p2.i := i;
        p2.j := j;
      end else
      if ch = 'o' then a[kk][i][j] := false;
    end;
    readln;
  end;
  readln;
end;
cur := 0; 
fillchar(b,sizeof(b),-1);
h := 1;
t := 1;
q[1][1] := p1.k;
q[1][2] := p1.i;
q[1][3] := p1.j;
w[p1.k][p1.i][p1.j] := true;
b[p1.k][p1.i][p1.j] := 0;
while check() and (h <= t) do begin
  x := q[h][1];
  y := q[h][2];
  z := q[h][3];
  cur := b[x][y][z] + 1;
  put(x,y-1,z);
  put(x,y,z-1);
  put(x,y,z+1);
  put(x,y+1,z);
  put(x+1,y,z);
  inc(h);
end;
{for kk := 1 to k do begin
  for i := 1 to n do begin
    for j := 1 to m do
      write(b[kk][i][j]:3);
    writeln;
  end;
  writeln;
end; }
write(cur * 5);
end.
